import { createStore, Store } from 'vuex';
import { InjectionKey } from 'vue';

// 定义 store1 的状态类型
interface Store1State {
	count : number;
}

// 定义 store1 的注入键
export const store1Key : InjectionKey<Store<Store1State>> = Symbol();

// 创建 store1 实例
export const store1 = createStore<Store1State>({
	state: {
		count: 0
	},
	mutations: {
		increment(state) {
			state.count++;
		},
		decrement(state) {
			state.count--;
		}
	},
	actions: {
		incrementAsync({ commit }) {
			setTimeout(() => {
				commit('increment');
			}, 1000);
		}
	},
	getters: {
		getCount(state) {
			return state.count;
		}
	}
});